import org.apache.flink.api.scala._

/**
 * @author:yehw
 * @date: 2021/1/21:下午9:27
 * @description: 第一题
 */
object WordCountScala {
  def main(args: Array[String]): Unit = {
    val startTile = System.currentTimeMillis()
    //输入路径
    val inputPath = "/Users/yehuaiwei/IdeaProjects/FirstFlink/input/wordCount.txt"
    val outPath = "/Users/yehuaiwei/IdeaProjects/FirstFlink/outPut"

    val environment = ExecutionEnvironment.getExecutionEnvironment
    //environment.setParallelism(1);
    environment.setParallelism(3);

    val files: DataSet[String] = environment.readTextFile(inputPath)
    val words = files.flatMap(_.split(" ")).map((_, 1)).groupBy(0).sum(1)
    val outPut = words.writeAsCsv(outPath, "\n", " ").setParallelism(1)
    environment.execute("scala");
    val endTime = System.currentTimeMillis()
    println("并行度是3时间是：" + (startTile - endTime));
  }
}
